<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>角色管理</title>
    <link rel="import" href="../includes/baseInclude.html">
    <style type="text/css">
        .ui-jqgrid tr.jqgrow td { white-space: normal !important; height:auto; }
        /*jqgrid首行背景色*/
        .ui-th-column{
            background-color:#ffffff !important;
            text-align: center !important;
            /*border: none !important;*/
        }
        /*表格去除竖线*/
        table.table-bordered td {
            border: none !important;
            text-align: center !important;
        }
        /*checkbox前面的*/
        #roleTableList_rn{
            width: 29px !important;
        }
        .ui-jqgrid-bdiv{
            border: none !important;
        }
        .ui-pg-input{
            border: none !important;
        }
        .ui-jqgrid-hbox{
            border: none !important;
        }
        .btn{
            background-image: url(../images/btn.png);
            margin-left: 15px;
            width: 85px;
            height: 55px;
            background-color: #ffffff;
            border: none;
            text-align: center;
        }
        .btn:hover{
            background-image: url(../images/btn_mouseOver.png);
            margin-left: 15px;
            color:#ffffff;
            width: 85px;
            height: 55px;
            background-color: #ffffff;
            border: none;
            text-align: center;
        }
        .btn:active{
            background-image: url(../images/btn_mouseOver.png);
            margin-left: 15px;
            color:#ffffff;
            width: 85px;
            height: 55px;
            background-color: #ffffff;
            border: none;
            text-align: center;
        }
        .btn:focus{
            outline: none;
            background-image: url(../images/btn_mouseOver.png);
            margin-left: 15px;
            color:#ffffff;
            width: 85px;
            height: 55px;
            background-color: #ffffff;
            border: none;
            text-align: center;
        }
    </style>
</head>
<body ng-app="roleApp" ng-controller="roleCtrl">
<div id="manage-area-title">
    <div class="pd-20">
        <div style="margin-bottom: 10px;" >
            <button class="btn" ng-click="datadel()">批量删除</button>
            <button class="btn" ng-click="layer_show('添加角色','roleManagement-add.html','800px','220px')">新增</button>
            <button class="btn">停止</button>
        </div>

        <div style="clear: both;"></div>
        <div  style="width: 100%;" class="jqGrid_wrapper">
            <table id="roleTableList" style="border: none;"></table>
            <div id="roleTableListPager"></div>
        </div>
    </div>
</div>
<script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
<!--<script type="text/javascript" src="/pc/base/js/laydate/laydate.js"></script>-->
<script type="text/javascript" src="../js/base/jqGrid.js"></script>
<script type="text/javascript" src="../js/libs/gridUtil.js"></script>
<!--<script type="text/javascript" src="../js/instruct.js"></script>-->
<script>
    //angularjs post 提交时HTTP头设置
    var transform = function (data) {
        return $.param(data);
    }, postCfg = {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        },
        transformRequest: transform
    };
    var app = angular.module('roleApp',[]);
    app.controller('roleCtrl',function($scope,$http){
        /*刷新*/
        $scope.reload = function(){
            $scope.projectName = "";
            $scope.search();
        }
//				/*搜索合同*/
//				$scope.projectName = "";
//				$scope.search = function(name){
//					var data = {'SalesBidding.name':name};
//					$("#roleTableList").setGridParam({
//						url:"/salesBidding/findBidding",
//						datatype: "json",
//						page:1
//					});
//					$("#roleTableList").setPostData(data);
//					$("#roleTableList").trigger("reloadGrid");
//				};

        //弹出框layerShow
        $scope.layer_show = function(title,url,width,height){
            layer.open({
                type:2,
                title:title,
                content:url,
                shadeClose:false,
                shade:0.2,
                maxmin: true,
                closeBtn:1,
                area: [width, height],
                end:function(){
                    refresh();//关闭layer,刷新方法
                }
            })
        };

        /*选中删除 checkBox*/
        function getSelectedIds(){
            $scope.selectedIds = $("#roleTableList").jqGrid("getGridParam", "selarrrow");
            return $scope.selectedIds;
        };
        /*批量删除*/
        $scope.datadel = function() {
            getSelectedIds();
            if($scope.selectedIds.length==0){//没有选择一个的时候提示
                layer.msg('请至少选中一条数据再操作！',{icon:2,time:1000});
                return;
            }else{
                layer.confirm('确定要删除么，操作需谨慎？',function(){
                    var dataManyDele={
                        'biddingIds':$scope.selectedIds
                    };
                    $http.post('/salesBidding/deleteBiddingBatch',dataManyDele,postCfg)
                            .success(function(resp){
                                if(validateSuccessData(resp)){
                                    layer.msg('删除成功',{icon:1,time:500});
                                    window.refresh();
                                }else{
                                    layer.msg(resp.errorMessage,{icon:2,time:1000});
                                }
                            });
                });
            };
        };

    });
</script>
<script>
    $(document).ready(function(){
        $("#roleTableList").jqGridFunction({
            url:'/role/findByPages',
            dataType:'json',
            postData:{},
            styleUI:'Bootstrap',
            autowidth:true,
            viewrecords:true,
            shrinkToFit:true,
            rowList:[10,20,50,100],
            colNames:['主键','操作','角色名称','描述','权限','状态'],
            colModel:[{name:'id',key:true,hidden:true},
                    {name:'operat',width:90,formatter:operatFormatter},
                    {name:'name',width:280},
                    {name:'description',sortable:true},
                    {name:'qx',sortable:true},
                    {name:'isAble',width:60,sortable:true},
            ],
            height:$(document).height()-$("#manage-area-title").height()-130,
            rownumbers: true, // 显示行号
            multiselect:true

        });
        $(window).bind('resize', function () {
            var width = $('.jqGrid_wrapper').width();
            $("#roleTableList").setGridWidth(width);
            // $("#roleTableList").setGridWidth($(window).width()*0.99);　
        });
			function operatFormatter(cellvalue, options, rowObject){
				var operateHtml = "";
				    operateHtml +='<a title="编辑" href="javascript:layer_shows('+rowObject.id+',1)" class="ml-5" style="text-decoration: none"><i class="Hui-iconfont">&#xe6df;</i></a>';
				    operateHtml +='<a title="删除" href="javascript:deleRole('+rowObject.id+')"  class="ml-5" style="text-decoration: none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
				return operateHtml;
			};
    });

    //弹出层
    function layer_shows(id,flag){
        if(flag == 1){
            var title = "编辑角色";
            var url = 'roleManagement-add.html?editId='+id+'&flagId='+'edit';
            var w = "800px";
            var h = "260px";
        }else{
            var title = "角色详情";
            var url = 'biddingManagement-detail.html?editId='+id+'&flagId='+'edit';
            var w = "800px";
            var h = "550px";
        }
        layer.open({
            type: 2,
            area: [w , h],
            fix: false, //不固定
            maxmin: true,
            shade:0.2,
            title: title,
            content: url,
            end:function(){
                refresh();
            }
        });
    }

    /*删除*/
    function deleRole(id){
        layer.confirm('确定要删除吗？操作需谨慎',function(){
            $.ajax({
                type:'post',
                dataType:'json',
                async:true,
                url:'/role/delete',
                data:{
                    'id':id
                },
                success:function(data){
                    if(data.errorMessage == null){
                        layer.msg('已删除!',{icon:1,time:500});
                        refresh();
                    }else{
                        layer.msg(data.errorMessage,{icon:2,time:1000})
                    }
                }
            });
        });
    }

    //		//高级搜索
    //		function biddingSearch(data){
    //			$("#roleTableList").setGridParam({
    //				url:"/salesBidding/findBidding",
    //				datatype: "json",
    //				page:1
    //			});
    //			$("#roleTableList").setPostData(data);
    //			$("#roleTableList").trigger("reloadGrid");
    //		}
    //刷新
    function refresh(){
        $("#roleTableList").trigger("reloadGrid");
    };


</script>
</body>
</html>